#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "string.h"
#include "stdlib.h"

#define LEDOFF 0 /* 关灯 */
#define LEDON  1 /* 开灯 */

int main(int argc,char *argv[])
{
    int fd,retvalue;
    char *filename;
    unsigned char ledstate[1];

    if (argc !=3)
    {
        printf("Error Usage!\r\n");
        return -1;
    }

    filename = argv[1];

    /* 打开驱动文件 */
    fd = open(filename,O_RDWR);
    if (fd < 0)
    {
        printf("Can't open file %s\r\n",filename);
        return -1;
    }

    ledstate[0] = atoi(argv[2]); 
    retvalue = write(fd,ledstate,sizeof(ledstate));
    if (retvalue < 0)
    {
        printf("LED Control failed!\r\n");
        close(fd);
        return -1;
    }
    


    /* 关闭设备 */
    retvalue = close(fd);
    if (retvalue < 0)
    {
        printf("Can't close file %s \r\n",filename);
        return -1;
    }
    
    return 0;
}


